package com.wanyang.vo;

import com.wanyang.exception.ApiException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiResult {
    private Integer code;
    private Object data;
    private String message;

    public static final Integer SUCCESS = 200;
    public static final Integer ERROR_REQUEST = 400;
    public static final Integer INNER_ERROR = 500;

    public static ApiResult success() {
        return ApiResult.builder()
                .code(SUCCESS)
                .message("success")
                .data(null)
                .build();
    }

    public static ApiResult success(Object data, String message) {
        return ApiResult.builder()
                .code(SUCCESS)
                .message(message)
                .data(data)
                .build();
    }

    public static ApiResult error(ApiException ex) {
        return ApiResult.builder()
                .code(ex.getCode())
                .message(ex.getMessage())
                .data(null)
                .build();
    }

    public static ApiResult error(Integer code, Object data, String message) {
        return ApiResult.builder()
                .code(code)
                .message(message)
                .data(data)
                .build();
    }

    public static ApiResult error(Object data, String message) {
        return ApiResult.builder()
                .code(INNER_ERROR)
                .message(message)
                .data(data)
                .build();
    }

}
